package com.zxc.service;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import com.zxc.util.DBUtil;

public class DBService {
	private static volatile List<DBUtil> dbSourceList;
	
	public DBService(){
		if(dbSourceList == null){
			synchronized(DBService.class){
				if(dbSourceList == null){
					dbSourceList = new ArrayList<DBUtil>();
				}				
			}
		}
	}

	
	public void add(DBUtil dbUtil){
		if(!dbSourceList.contains(dbUtil)){
			dbSourceList.add(dbUtil);
		}
		
	}
	
	public void remove(DBUtil dbUtil){
		dbSourceList.remove(dbUtil);
	}
	
	public List<DBUtil> getDBSourceList(){
		return Collections.unmodifiableList(dbSourceList);
	}
	
	public String[] getDBNames(){
		String[] names = new String[dbSourceList.size()];
		for(int i = 0;i<names.length;i++){
			names[i] = dbSourceList.get(i).toString();
		}
		return names;
	}
}
